import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:shop/shop/merchant/GoodsList.dart';
import 'package:shop/shop/merchant/MyOrderList.dart';
import 'package:shop/shop/merchant/MyCenter.dart';
import 'package:shop/shop/merchant/YuYueListPage.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

class Index extends StatefulWidget {
  final String showIndex;
  final String mType;
  Index({Key key, this.title, this.showIndex,this.mType}) : super(key: key);

  final String title;

  @override
  _Index createState() => _Index();
}
class _Index extends State<Index>  with SingleTickerProviderStateMixin {

  TabController controller;
  SharedPreferences prefs;
  String mType = "0";//商户类型

  @override
  void initState() {
    this.mType = widget.mType;
    controller = new TabController(length: 3, vsync: this,initialIndex: int.parse(widget.showIndex));
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      // 配置本地化
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('zh', 'CH'),
        const Locale('en', 'US'),
      ],
      locale: const Locale("zh"),
      home: new Scaffold(
        body: new TabBarView(
          controller: controller,
          children: <Widget>[
            mType=="0" ? MyOrderList() : YuYueListPage(),
            GoodsList(),
            MyCenter(),
          ],
        ),
        bottomNavigationBar: new Material(
          color: Colors.white,
          child: new TabBar(
            controller: controller,
            labelColor: Colors.lightBlue,
            unselectedLabelColor: Colors.black26,
            tabs: <Widget>[
              new Tab(
                text: mType=="0" ? "我的订单" : "预约订单",
                icon: new Icon(Icons.list),
              ),
              new Tab(
                text: mType=="0" ? "商品管理" : "服务管理",
                icon: new Icon(Icons.burst_mode_outlined),
              ),
              new Tab(
                text: "我的店铺",
                icon: new Icon(Icons.home),
              ),
            ],
          ),
        ),
      ),
    );
  }

}